set -e


echo "format disk"

mkfs.fat -F 32 /dev/sda1
mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda3

echo "mout disk"
mount /dev/sda2 /mnt
mount --mkdir /dev/sda1 /mnt/boot
mount --mkdir /dev/sda3 /mnt/home

echo "make swapfile"

dd if=/dev/zero of=/mnt/swapfile bs=1M count=8192 status=progress
chmod 0600 /mnt/swapfile
mkswap -U clear /mnt/swapfile
swapon /mnt/swapfile

#echo "maike mirrors"
#reflector -p https -c China --delay 3 --completion-percent 95 --sort rate --save /etc/pacman.d/mirrorlist


echo "install base"
pacstrap -K /mnt base linux linux-firmware

genfstab -U /mnt >> /mnt/etc/fstab

cp installNewSystem.sh /mnt/home/installNewSystem.sh

echo "done use \"arch-chroot /mnt  \" swich to new system"
